<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('表格父子视图')" />
	    <th:block th:include="include :: select2-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>打卡年份：</label>
                                <input type="text" name="clockYear"/>
                            </li>
                            <li>
                                <label>打卡月份：</label>
                                <input type="text" name="clockMonth"/>
                            </li>
                            <li>
                                <label>部门（精确查询）：</label>
                                <!-- <input type="text" name="personProjectId"/> -->
                                <select id="selBM" class="form-control"
			                        name="dept1"
			                        data-ajax--url="/system/dept/select2"
			                        data-placeholder="请选择部门">
								</select>
                            </li>
                            <li>
                                <label>部门（模糊查询）：</label>
                                <input type="text" name="deptName1"/>
                            </li>
                            
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="resetForm()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            
           <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:clock:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
			
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table"></table>
			</div>
		</div>
	</div>
    <div th:include="include :: footer"></div>
        <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var prefix = ctx + "system/dclock";

        function resetForm(){
        	//$('#selP').
        	$("#selP").val(null).trigger('change');
        	$("#selP").html("");
        	
        	$("#selPR").val(null).trigger('change');
        	$("#selPR").html("");
        	
        	$("#selBM").val(null).trigger('change');
        	$("#selBM").html("");
        	
        	$("#selBM2").val(null).trigger('change');
        	$("#selBM2").html("");
        	
        	$.form.reset();
        }
        
        $(function() {
            var options = {
                url: prefix + "/report",
                exportUrl: prefix + "/exportrep",
		        showSearch: false,
		        showRefresh: true,
		        showToggle: false,
		        showColumns: true,
		        detailView: true,
		        modalName: "汇总报表",
				onExpandRow : function(index, row, $detail) {
					initChildTable(index, row, $detail);
				},
                columns: [
	                {
			            checkbox: true
			        },
					/* {
						field : 'personId', 
						title : '用户ID'
					}, */
					{
						field : 'clockYear', 
						title : '年份'
					},
					{
						field : 'clockMonth', 
						title : '月份'
					},
					{
						field : 'deptName1', 
						title : '部门1'
					},
					 {
						field : 'deptName2', 
						title : '部门2'
					}, 
					{
						field : 'position_name', 
						title : '设备位置'
					},
					{
						field : 'device_name', 
						title : '设备名称'
					},
					{
						field : 'user_name', 
						title : '用户姓名'
					}
				]
            };
            $.table.init(options);
        });
        
		initChildTable = function(index, row, $detail) {
			var childTable = $detail.html('<table style="table-layout:fixed"></table>').find('table');
    	    $(childTable).bootstrapTable({
    	        url: prefix + "/reportdetail",
    	        method: 'post',
    	        sidePagination: "server",
    	        contentType: "application/x-www-form-urlencoded",
    	        
    	        /* queryParams : {
                    personId: row.personId
				}, */
				queryParams: (params)=>{
					return {
						startPersionId:row.startPersionId,
						dept1: row.dept1,
						dept2: row.dept2,
						clockYear: row.clockYear,
						clockMonth: row.clockMonth,
						deviceId: row.deviceId
					};
				},
    	        columns: [{
					field : 'project_code', 
					title : '项目编号'
				},{
					field : 'project_name', 
					title : '项目名称'
				},
				{
                    field: 'project_status',
                    title: '项目状态',
                    align: 'center',
                    formatter: function(value, row, index) {
                    	return value == 0 ? "正常" : value == 1 ? "结束" : "";
                    }
                },
				{
					field : 'countTime', 
					title : '总时长'
				}]
    	    });
		};
    </script>
</body>
</html>